﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    public sealed partial class WorkItemLogCollection
    {
        #region Public Members

        #region MinimumExecutionStartTime

        public WorkItemLog MinimumExecutionStartTime
        {
            get
            {
                WorkItemLog workItemLog;

                workItemLog = null;
                foreach (var item in this)
                {
                    if (workItemLog == null)
                        workItemLog = item;
                    else if (workItemLog.ExecutionStartTime > item.ExecutionStartTime)
                        workItemLog = item;
                }
                return workItemLog;
            }
        }

        #endregion

        #region Add

        public void Add(WorkItemLog item, int maxCount)
        {
            Add(item);
            if (this.Count > maxCount)
            {
                item = this.MinimumExecutionStartTime;
                Remove(item);
            }
        }

        #endregion

        #endregion
    }
}